package com.atguigu.day01;

public class Example6 {
    public static void main(String[] args) {
        System.out.println(add(1,2));
        System.out.println(add("a", "b"));
        System.out.println(add("a", 1));
    }

    public static String add(Object a, Object b) {
        if (a instanceof Integer && b instanceof Integer) {
            return (Integer) a + (Integer) b + "";
        } else if (a instanceof String && b instanceof String) {
            return a.toString() + b.toString();
        } else {
            throw new RuntimeException("类型错误");
        }
    }
}
